
<?php

//连接数据库
try {
    $db = new PDO('mysql:dbname=books;host=127.0.0.1','root','123456');

    $add= $db->prepare('insert into book (bookid,bookName,press,price,status) values(:bookid,:bookName,:press,:price,:status)');
    $data[':bookid']=$_POST['bookid'];
    $data[':bookName']=$_POST['bookName'];
    $data[':press']=$_POST['press'];
    $data[':price']=$_POST['price'];
    $data[':status']=0;
    if($add->execute($data)){
        echo "<script>  location.href='../html/searchBook.php';</script>";
    }else{
        echo "<script> alert('添加失败!'); location.href='#'</script>";


    }
} catch (PDOException $e) {
    echo 'Connection failed';
}
?>

       
      